import time
from datetime import datetime

from pywinauto import Application

#操作微信对话框
app = Application(backend='uia').connect(process=12816)
#定位窗口
win = app.window(title="文件传输助手")
win.wait('visible')
#获取消息发送之前的消息数据
message_list_before = win.child_window(title='消息', control_type='List')
message_count_before = message_list_before.item_count()

#发送消息
#(1)定位到消息输入框
edit = win.child_window(title='输入', control_type='Edit')
#(2)输入消息
edit.click_input()
message = "-----小钱子-" + str(datetime.now())
edit.type_keys(message, with_spaces=True)
#(3)发送消息
send = win.child_window(title='发送(S)', control_type='Button')
send.click_input()

#获取消息发送之后的消息数量
message_list_after = win.child_window(title='消息', control_type='List')
message_count_after = message_list_after.item_count()

#校验消息数量是否增加 (+1 or +2)
print(message_count_before, message_count_after)
# assert message_count_after == message_count_before + 1 or message_count_after == message_count_before + 2
#校验消息列表最后一条消息是否是对应的消息
text = message_list_after.get_item(row=message_list_after.item_count()-1).window_text()
print(text)